package com.hqyj.dao;




import com.hqyj.entity.House;
import org.apache.ibatis.annotations.Delete;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;

@Repository
public interface HouseDao extends JpaRepository<House,Integer> {

    @Query(nativeQuery = true,value = "select*from house ")
    List<House> getAll();
//    @Query(value = "select * from house }", nativeQuery = true)
//    Page<House> search(Pageable pageable);

/*    @Query(nativeQuery = true,value = " select * from  house h where h.houseaddress like CONCAT('%',:name,'%') ")
    List<House> findByHouseaddressLike(@Param("name") String houseaddress);*/

    @Query(value = "Select * From house where house_id = :house_id" ,nativeQuery = true)
    House getOne(int house_id);

    @Transactional
    @Modifying
    @Query(value = "update house set housestate =:#{#house.housestate} where house_id=:#{#house.house_id}",nativeQuery = true)
    int updateById(@Param("house") House house);

    @Transactional
    @Modifying
    @Query(value = "insert into house(housename,houseaddress,housetype,housesize,houseprice,housestate,user_id,jpg) values(:housename,:houseaddress,:housetype,:housesize,:houseprice,:housestate,:user_id,:jpg) ",nativeQuery = true)
    int add( @Param("housename") String housename,
             @Param("houseaddress") String houseaddress,
             @Param("housetype") String housetype,
             @Param("housesize") String housesize,
             @Param("houseprice") String houseprice,
             @Param("housestate") String housestate,
             @Param("user_id") Integer user_id,
             @Param("jpg") String jpg);



    @Query(value = "update house set houseaddress = :houseaddress, housetype = :housetype, housesize = :housesize where house_id = :house_id",nativeQuery = true)
    int updateById(@Param("house_id") Integer house_id, @Param("houseaddress") String houseaddress,String housetype,String housesize);



//    Page<House> findByHouseaddress(String username,Pageable pageable);

}